package cn.itcast.action;

import cn.itcast.entity.Admin;
import cn.itcast.service.IAdminService;

/**
 * 管理员登陆注册模块
 * 1. 登陆
 * @author Jie.Yuan
 *
 */
public class AdminAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	// 封装请求数据
	private Admin admin;

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}
	
	// 调用Service
	private IAdminService adminService;
	public void setAdminService(IAdminService adminService) {
		this.adminService = adminService;
	}
	
	/**
	 * 登陆
	 */
	public String login(){
		// 登陆验证
		Admin adminInfo = adminService.login(admin);
		// 验证
		if(adminInfo == null){
			// 登陆失败
			return "loginFailed";
		}else{
			// 登陆成功, 保存数据到session
			getMapSession().put("adminInfo", adminInfo);
			return "index";
		}
	}
}
